<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>测试</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.12/themes/default/style.min.css" />
    <style>
        #tree {
            margin: 20px;
            padding: 10px;
            border: 1px solid #f5f5f5;
            width: 300px;
            height: 500px;
            overflow-y: auto;
        }

    </style>
</head>
<body>
<h1>菜单</h1>
<div>
    <div id="tree"></div>
</div>


<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jstree/3.3.12/jstree.min.js"></script>
<script>
    $(document).ready(function() {
        $.ajax({
            url: '/menu/getSubkeyTree',
            type: 'GET',
            data: { perId: 1 },  // Replace with your perId
            success: function(response) {
                if (response.code === 200) {
                    $('#tree').jstree({
                        'core': {
                            'data': formatData(response.data)
                        }
                    });
                } else {
                    alert(response.message);
                }
            },
            error: function() {
                alert('请求失败');
            }
        });

        function formatData(data) {
            // Transform the data format if needed
            return data.map(item => ({
                'id': item.id,
                'text': item.name,
                'children': item.children ? formatData(item.children) : []
            }));
        }
    });
</script>
</body>
</html>
